

import java.io.File;
import java.util.ArrayList;

import strategies.Strategy;

import Data.HibernateUtil;

import main.Declarations;

public class TagByType implements Strategy{
	private String strategyName;
	
	
	@Override
	public String getStrategyName() {
		// return the name of the strategy
		return strategyName;
	}
	@Override
	public void setStrategyName(String strategyName) {
		this.strategyName = strategyName;	
	}
	
	
	@Override
	public ArrayList<String> dataForGUI() {
		ArrayList<String> tagsList = new ArrayList<String>();
		
		tagsList.add("Document file");
		tagsList.add("Excel File");
		tagsList.add("PowerPoint File");
		tagsList.add("Text File");
		
		tagsList.add("Mp3 File");
		tagsList.add("Avi File");
		tagsList.add("Zip File");
		tagsList.add("Pdf File");
		tagsList.add("Jpg File");
		tagsList.add("BMP File");
		tagsList.add("xml File");
		tagsList.add("dtd File");
		tagsList.add("java File");
		tagsList.add("dll File");
		tagsList.add("class File");
		tagsList.add("url File");
		
		return tagsList;
	}


	@Override
	public ArrayList<String> searchFiles(String tag) {
		ArrayList<String> filesNames = new ArrayList<String>();
		
		//get all the files with the proper tag
		filesNames = HibernateUtil.instance.searchFilesByStrategy(strategyName, tag);
		//return the list of the files names 
		return filesNames;
	}



	@Override
	public String tag(String fileName) {
		//create a file with the path and the name of the file
		File file = new File(Declarations.instance.getPath() + "\\" + fileName);
		String tag;
		
		//index where start suffix
		int idx = fileName.indexOf(".");
		//check if the file exists
		if((file.exists())&&(idx != -1)){
			//find the suffix of the file
			String tmpSuffix = fileName.substring(idx+1);
			//small letters
			String suffix = tmpSuffix.toLowerCase();
			
			
			if((suffix.equals("doc"))||(suffix.equals("docx"))){
				tag = "Document file";
			}
			else if((suffix.equals("xls"))||(suffix.equals("xlsx"))){
				tag = "Excel File";
			}
			
			else if((suffix.equals("ppt"))||(suffix.equals("pptx"))){
				tag = "PowerPoint File";
					
			}
			else if(suffix.equals("txt")){
				tag = "Text File";
			}
			else if(suffix.equals("mp3")){
				tag = "Mp3 File";
			}
			else if(suffix.equals("avi")){
				tag = "Avi File";
			}
			else if(suffix.equals("zip")){
				tag = "Zip File";					
			}
			else if(suffix.equals("jpg")){
				tag = "Jpg File";
			}
			else if(suffix.equals("bmp")){
				tag = "BMP File";
			}
			else if(suffix.equals("xml")){
				tag = "xml File";
			}
			else if(suffix.equals("dtd")){
				tag = "dtd File";
			}
			else if(suffix.equals("java")){
				tag = "java File";
			}
			else if(suffix.equals("dll")){
				tag = "dll File";
			}
			else if(suffix.equals("class")){
				tag ="class File";
			}
			else if(suffix.equals("url")){
				tag = "url File";
			}
			//case not one of them
			else{
				tag = "other";
			}
			return tag;
		}
		//case the file don't exists
		else{
			return null;
		}
	}
	//end of tag

}
